package main

import (
	"Ginproject/GinProject/DataBindAndVerify/src"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
)

func main() {
	router := gin.Default()
	router.LoadHTMLGlob("template/**/*")

	router.Static("/static", "./static")

	v, ok := binding.Validator.Engine().(*validator.Validate)
	if ok {
		v.RegisterValidation("len_valid", src.LenValid)
	}

	// 数据绑定
	router.GET("/bindform", src.BindForm)
	router.POST("/dobindform", src.DoBindForm)
	router.GET("/bindquery", src.BindQuery)
	router.GET("/bindjson", src.BindJson)
	router.POST("/bindjsonpost", src.BindJsonPost)
	router.GET("/bindurl/:name/:age/:addr", src.BindUrl)
	// 数据验证
	router.GET("/tovalid", src.ToValidDate)
	router.POST("/dovalid", src.DoValidDate)
	router.POST("/dovalid2", src.DoValidDate2)

	router.Run(":8080")
}
